﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using _MetalSlug.Form.ScreenSystem;
using _MetalSlug.Form.PlayGame;
using Microsoft.Xna.Framework.Input;
using _MetalSlug.Form.ScreenSystem.Message;

namespace _MetalSlug.Form.GameOver
{
    public class GameOverScreen:MyScreen
    {
        int GameCore;
        List<Texture2D> FontCore;
        public GameOverScreen()
        {
            LoadContent();
            InitialAttribute();
        }

        public override void LoadContent()
        {
            Background = GameUtil.LoadTexture("gameover");
            FontCore = GameUtil.LoadTextures("Font/font3/num", 10);
        }

        public override void InitialAttribute()
        {
            TypeOfWindow = TYPE.GAMEOVER;
        }

        public override void Update(GameTime gameTime)
        {
            HandleKeyboard();
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            //draw Score 
            int temp = GameCore;
            for (int i = 0; i < 6; i++)
            {
                int x = temp % 10;
                temp /= 10;
                spriteBatch.Draw(FontCore[x], new Rectangle(350 + (6 - i) * 25, 90, 40, 51), Color.White);
            }
        }

        public override void HandleKeyboard()
        {
            if (UserInput.isKeyClicked(Keys.Escape))
            {
                this.Send(MyScreen.TYPE.MAINMENU, MyMessage.TYPE.SHOW, null);
            }
        }

        public override void Receive(MyScreen SendWindow, MyMessage SendMessage)
        {
            if(SendMessage.TypeOfMessage == MyMessage.TYPE.SHOW && 
                SendWindow.TypeOfWindow == TYPE.PLAYGAME)
            {
                GameCore = ((PlayGameScreen)SendWindow).GetGameCore();
            }

            SendWindow.Reset();
        }
    }
}
